package it.gtd.swimpool.model.entity;

import com.google.common.annotations.Beta;

import javax.persistence.Embeddable;
import javax.persistence.ManyToOne;
import java.io.Serializable;

import static com.google.common.base.Preconditions.checkNotNull;

@Embeddable
@Beta
class FriendshipRequestId implements Serializable {
    @ManyToOne
    private User sender;

    @ManyToOne
    private User target;


    public User getSender() {
        return sender;
    }

    public void setSender(User sender) {
        checkNotNull(sender, "sender can't be null");

        this.sender = sender;
    }

    public User getTarget() {
        return target;
    }

    public void setTarget(User target) {
        checkNotNull(target, "target can't be null");

        this.target = target;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof FriendshipRequestId)) return false;

        FriendshipRequestId that = (FriendshipRequestId) o;

        if (!sender.equals(that.sender)) return false;
        if (!target.equals(that.target)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = sender.hashCode();
        result = 31 * result + target.hashCode();
        return result;
    }
}
